package com.zmc.lostfound.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ZMC
 * @description Elasticsearch配置类
 */
@Configuration
public class ElasticsearchConfig {

    public static final RequestOptions COMMON_OPTIONS;

    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        COMMON_OPTIONS = builder.build();
    }

    /**
     * @return RestHighLevelClient
     * @description 向Spring容器注入RestHighLevelClient的Bean, 用于后续操作Elasticsearch的JavaApi
     */
    @Bean
    public RestHighLevelClient esRestClient() {
        return new RestHighLevelClient(RestClient.builder(
                HttpHost.create("http://43.142.234.201:9200")
        ));
    }

}
